package com.web.dao;

import com.web.entity.OrderGoods;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface OrderGoodsMapper {


    @Delete({
            "delete from t_order_goods ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_order_goods (order_id, good_id,",
            " title,image, price, num, ",
            " create_time, modify_time) ",
            " values (#{orderId,jdbcType=BIGINT}, #{goodId,jdbcType=BIGINT}, ",
            " #{title,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{num,jdbcType=INTEGER}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(OrderGoods record);

    @InsertProvider(type = OrderGoodsSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(OrderGoods record);


    @Select({
            "select",
            " id, order_id, good_id, title,image, price, num, create_time, modify_time ",
            " from t_order_goods ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT),
            @Result(column = "good_id", property = "goodId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
            @Result(column = "num", property = "num", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    OrderGoods selectByPrimaryKey(Long id);


    @UpdateProvider(type = OrderGoodsSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderGoods record);

    @Update({
            "update t_order_goods ",
            " set order_id = #{orderId,jdbcType=BIGINT},",
            " good_id = #{goodId,jdbcType=BIGINT},",
            " title = #{title,jdbcType=VARCHAR},",
            " image = #{image,jdbcType=VARCHAR},",
            " price = #{price,jdbcType=DECIMAL},",
            " num = #{num,jdbcType=INTEGER},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP} ",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderGoods record);

    @Select({
            "select ",
            " id, order_id, good_id, title,image, price, num, create_time, modify_time ",
            " from t_order_goods ",
            " where order_id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT),
            @Result(column = "good_id", property = "goodId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
            @Result(column = "num", property = "num", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<OrderGoods> selectByOrderId(Long id);

}